﻿<%@ Page Title="Vagas" Language="C#" MasterPageFile="~/Site.Master" AutoEventWireup="true"
    CodeBehind="Vagas.aspx.cs" Inherits="RzCorportativo.Views.Cadastros.Vagas" %>

<asp:Content ID="Content1" ContentPlaceHolderID="HeadContent" runat="server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="LeftContent" runat="server">
</asp:Content>
<asp:Content ID="Content3" ContentPlaceHolderID="MainContent" runat="server">
    <div class="tabbable tabs-left">
        <div class="span12">
            <%if (RzCorportativo.AppSession.Login != null && RzCorportativo.AppSession.Login.TipoLogin == RzCorportativo.Lib.TipoLogin.Empresa)
              { %>
            <div class="controls controls-row">
                <input type="button" name="btnNovo" value="novo" id="btnNovaVaga" class="btn btn-success" />
            </div>
            <%} %>
            <br />
            <div class="controls controls-row">
                <div dataspy="">
                    <table class="table table-hover" id="gridVagas" runat="server">
                        <thead>
                            <tr>
                                <th>
                                    CÓDIGO
                                </th>
                                <th>
                                    CARGO
                                </th>
                                <th>
                                    DATA
                                </th>
                                <th>
                                    #
                                </th>
                            </tr>
                        </thead>
                        <tbody>
                        </tbody>
                    </table>
                </div>
            </div>
        </div>
        <script type="text/javascript">
            $(function () {
                $.ajax({
                    url: '<%=this.ResolveUrl("~/Views/Cadastros/Vagas.aspx/Listar")%>',
                    type: "POST",
                    dataType: "json",
                    contentType: "application/json; charset=utf-8",
                    data: '',
                    /*success: function (e) {
                    var vagas = e.d;
                    for (var i in vagas) {

                    vagas[i].DataCadastro = new Date(parseInt(vagas[0].DataCadastro.substr(6)));

                    var tbody = "<tr vaga='" + vagas[i].VagaId + "'><td>" + vagas[i].VagaId + "</td><td>" + vagas[i].Cargo.Nome +
                    "</td><td>" + vagas[i].DataCadastro.getDate() + "/" + (vagas[i].DataCadastro.getMonth() + 1) + "/" + vagas[i].DataCadastro.getFullYear() +
                    "</td><td><div class='btn-group' data-toggle='buttons-radio'><input type='button' value='gerenciar' class='btn' onclick='btnGerenciarOnClick(\"" + vagas[i].VagaId + "\");'/>" +
          
                            
                              
                    "<input type='button' id='btnRemove' onclick='RemoveItem(" + vagas[i].VagaId + ", this)' class='btn btn-danger' value='remover'/></div></td>" +
                    "</tr>";

                    $('table[id$="gridVagas"] tr:last').after(tbody);

                    }
                    },*/
                    success: success,
                    error: function (e) {

                    }
                });
            });
        </script>
    </div>
    <%if (RzCorportativo.AppSession.Login != null && RzCorportativo.AppSession.Login.TipoLogin == RzCorportativo.Lib.TipoLogin.Interno)
      {%>
    <script type="text/javascript">
        function success(e) {
            var vagas = e.d;
            for (var i in vagas) {
                vagas[i].DataCadastro = new Date(parseInt(vagas[i].DataCadastro.substr(6)));
                var tbody = "<tr vaga='" + vagas[i].VagaId + "'><td>" + vagas[i].VagaId + "</td><td>" + vagas[i].Cargo.Nome +
                            "</td><td>" + vagas[i].DataCadastro.getDate() + "/" + (vagas[i].DataCadastro.getMonth() + 1) + "/" + vagas[i].DataCadastro.getFullYear() +
                            "</td><td><div class='btn-group' data-toggle='buttons-radio'>" +
                            "<input type='button' id='btnIndicar' onclick='Indicar(" + vagas[i].VagaId + ", this)' class='btn btn-primary' value='indicações'/></div></td>" +
                            "</tr>";
                $('table[id$="gridVagas"] tr:last').after(tbody);
            }
        }
    </script>
    <%}
      else
      { %>
    <script type="text/javascript">
        function success(e) {
            var vagas = e.d;
            for (var i in vagas) {
                vagas[i].DataCadastro = new Date(parseInt(vagas[i].DataCadastro.substr(6)));
                var tbody = "<tr vaga='" + vagas[i].VagaId + "'><td>" + vagas[i].VagaId + "</td><td>" + vagas[i].Cargo.Nome +
                            "</td><td>" + vagas[i].DataCadastro.getDate() + "/" + (vagas[i].DataCadastro.getMonth() + 1) + "/" + vagas[i].DataCadastro.getFullYear() +
                            "</td><td><div class='btn-group' data-toggle='buttons-radio'><input type='button' value='gerenciar' class='btn' onclick='btnGerenciarOnClick(\"" + vagas[i].VagaId + "\");'/>" +
                            "<input type='button' id='btnRemove' onclick='FecharVaga(" + vagas[i].VagaId + ", this)' class='btn btn-danger' value='fechar vaga'/></div></td>" +
                //"<input type='button' id='btnRemove' onclick='RemoveItem(" + vagas[i].VagaId + ", this)' class='btn btn-danger' value='remover'/></div></td>" +
                            "</tr>";
                $('table[id$="gridVagas"] tr:last').after(tbody);
            }
        }
    </script>
    <%} %>
    <script type="text/javascript">
        $(function () {
            $("input[id='btnNovaVaga']").click(function () {
                window.location.href = '<%=this.ResolveUrl("~/Views/Cadastros/vaga.aspx")%>';
            });
        });
        function btnGerenciarOnClick(id) {
            window.location.href = '<%=this.ResolveUrl("~/Views/Cadastros/vaga.aspx?vagaid=")%>' + id;
        }
        function Indicar(vagaId) {
            window.location.href = '<%=this.ResolveUrl("~/Views/Cadastros/indicacao.aspx?vagaid=")%>' + vagaId;
        }
        function FecharVaga(vagaId) {
            $.ajax({
                url: '<%=this.ResolveUrl("~/Views/Cadastros/Vagas.aspx/Fechar")%>',
                type: "POST",
                dataType: "json",
                contentType: "application/json; charset=utf-8",
                data: '{ vagaId: ' + vagaId + '}',
                success: function (e) {
                    var vagas = e.d;
                    if (e.d.AlertType == AlertType.Success) {
                        $("tr[vaga='" + vagaId + "']").remove()
                    }
                    var alerta = new Alert();
                    alerta.Name = "erroGeral";
                    alerta.Type = e.d.AlertType;
                    for (var i in e.d.Messages) {
                        alerta.AddMessage(e.d.Messages[i]);
                    }
                    if (e.d.Show && e.d.Show == true) {
                        alerta.Show();
                    }
                },
                error: function (e) {

                }
            });
        }
    </script>
</asp:Content>
